
<template>
	<view>
		<view class="nav-wrap">
			<nav-bar ref="navBarChild" :navs="navs" :counts="navCounts" :current="navCurrent" @onChange="onNavBarChange" @onHeightChange='heightChange' @onBatch="batchChange" @onConfirm='handelConfirm' :dicData="dicData" :perData="personData" :dataTimeList='dataTimeList'></nav-bar>
		</view>
		<item-index-list :dataList="listData" :dicData="dicData" :tabChecked='tabChecked' :showCheckBox="showChk" :marginTopStyle='marginTopStyle' @getPro="getProId"/>
		<mix-float-menu @onBtnClick="clickFloatBtn" @cancel="canceles" @onClose="close" @add="addNewPage" :hiddenShow='hiddenShow'></mix-float-menu>
	</view>
</template>

<script>
	import navBar from "./components/min-nav-bar.vue"
	import itemIndexList from './components/item-index.vue';
	import mixFloatMenu from './components/flot-meau.vue';
	import app from '../../App.vue'
	export default {
		components: {
			mixFloatMenu,
			itemIndexList,
			navBar
		},
		data() {
			return {
				listData:[],
				navCounts: [0,0], //订单数量
				navs: [
					{name: '报送信息'},
					{name: '本季跟进'},
				],
				total:null,
				pageNumber:1,
				moreTip:false,
				navCurrent: 0, //当前tab
				tabChecked:0,//当前选中tab
				hiddenShow:false,
				dataList:[
					
				],//列表参数
				personData:[],
				showChk: false,
				projectId:'',//项目主键
				dataid:'',//
				projectName:'',
				dicData:{},
				getFormdata:{},//刷选条件
				marginTopStyle:80,
				showTimes:true,
				dataTimeList:[],
				batches:'',
				
			}
		},
		methods: {
			changepopup(e) {
				console.log('popup ' + e.type + ' 状态', e.show)
			},
			downCallback(e){
				this.refreshList();
			},
			handelConfirm(formdata){
				console.log('formdata',formdata)
				const formsData = {...this.getFormdata,...formdata};
				this.getFormdata = formsData;
				this.refreshList();
				// this.getDataList(this.navCurrent)
			},
			//获取角标数字
			async getDataNumber(){
				let url=''
				uni.showLoading()
				url=`bus/projquarter/ajaxSearch.do`
				//列表
				const basicParams ={
					pageSize: 10, //每页条数
					pageNo: this.pageNumber, //页码
					sortField: "", //排序字段
					sortOrder: "", //排序方向
					moduleId:'busProj', //固定值
					searchText:[],
				}
				const params = {...this.getFormdata,...basicParams,...this.batches}
				if(params.MANAGER==''){
					delete params.MANAGER
				}
				const res  = await this.$req({
					url:url,
					method:'POST',
					data: params
				})
				uni.hideLoading()
				if(res.data.success){
						this.navCounts[1]=res.data.attributes.total
				} else {
					uni.showToast({
						title:res.data.message,
						icon:'none'
					})
				}
			},
			async getDataList(numCode){
				let url=''
				uni.showLoading()
				this.listData={}
				if(numCode===0){
					url= `bus/reportview/ajaxSearch.do`
				}else{
					url=`bus/projquarter/ajaxSearch.do`
				}
				//列表
				const dicData = JSON.parse(uni.getStorageSync('dicData'));
				const basicParams ={
					pageSize: 10, //每页条数
					pageNo: this.pageNumber, //页码
					sortField: "", //排序字段
					sortOrder: "", //排序方向
					moduleId:'busProj', //固定值
					searchText:[],
				}
				const params = {...this.getFormdata,...basicParams,...this.batches}
				if(params.MANAGER==''){
					delete params.MANAGER
				}
				const res  = await this.$req({
					url:url,
					method:'POST',
					data: params
				})
				uni.hideLoading()
				if(res.data.success){
					const list = this.listData;
					const rows = [...res.data.attributes.rows]
					rows.forEach(item=>{
						item.industry = item.INDUSTRY ? this.$util.queryDicName(dicData,'inve_field', item.INDUSTRY) : ''
						item.projState = item.PROJ_STAGE ? this.$util.queryDicName(dicData,'busProjStage', item.PROJ_STAGE) : ''
						item.checked=false
						console.log(item.checked,"item.checked~~~~~~~~~~~~")
					})
					if(numCode===0){
						this.navCounts[0]=res.data.attributes.total
					}else{
						this.navCounts[1]=res.data.attributes.total
					}
					
					let newArr = [];
					newArr = this.pageNumber <=1 ? rows : list.concat(rows)
					this.listData = newArr;
					this.total = res.data.attributes.total
				} else {
					uni.showToast({
						title:res.data.message,
						icon:'none'
					})
				}
			},
			//数据字典
			
			//跟进人
			async getFlPerson(){
				const ret = await this.$req({
					url:'bus/proj/filter.do',
					data:{moduleId: 'busProj'}
				})
				if(ret.data.success){
					this.personData = ret.data.attributes.zdyDataSource.personDataSourceManage
				}
			},
			getDicName(data,value){
				const res = data.filter(function(item){
					return value === item.CODE
				})[0].CODE_NAME;
				return res;
			},
			loadData(e){
				this.mescroll.endSuccess(this.listData.length); //结束加载状态
			},
			mescrollInit(mescroll){
				// this.isLoading = true;
				this.mescroll = mescroll;
				this.mescroll.resetUpScroll(false)
			},
			onNavBarChange(current){
				this.showChk = false;
				if(this.navCurrent === current){
					return;
				}
				this.navCurrent = current;
				this.tabChecked=current
				if(current==0){
					this.hiddenShow=true
					if(this.showTimes){
						this.marginTopStyle=310
					}else{
						this.marginTopStyle=110
					}
				}else{
					this.marginTopStyle=80
					this.hiddenShow=false
				}
				this.refreshList();
			},
			heightChange(num){
				if(this.navCurrent===0){
					if(num===200){
						this.showTimes=true
						this.marginTopStyle=310
					}else{
						this.showTimes=false
						this.marginTopStyle=110
					}
				}else{
					this.marginTopStyle=80
				}
			
			},
			batchChange(batch){
				this.batches={
					BATCH:batch
				}
				 this.getDataList(this.navCurrent)
			},
			//刷新列表
			refreshList(){
				this.mescroll && this.mescroll.resetUpScroll(false)
				this.getFlPerson()
				this.getDataList(this.navCurrent)
				if(uni.getStorageSync('dicData')){
					this.dicData = JSON.parse(uni.getStorageSync('dicData'))
				}
			},
			clickFloatBtn() {
				this.showChk = true
			},
			close() {
				this.showChk = false;
			},
			// 点击取消送报
			async canceles(){
				let self=this
				if (!this.dataid) {
					uni.showToast({
						title: "请选择一条数据",
						icon: "none"
					})
					return;
				}
				uni.showModal({
					title: `确定要取消<${this.projectName}>送报吗?`,
					async success(e) {
						if (e.confirm) {
							uni.showLoading()
							self.showChk = false;
							const res = await self.$req({
								url:'bus/reportview/del.do',
								data:{
									selectedIds:self.dataid
								}
							})
							uni.hideLoading()
							if(res.data.success){
								uni.showToast({
									title:'取消送报成功',
									icon:'none'
								})
								self.refreshList()
							}else{
								uni.showToast({
									title:res.data.messages[0].content,
									icon:'none'
								})
							}
						}
					}
				})
			},
			//改变显示状态
			changeSta(){
				this.showChk = false;
			},
			//获取点击的item  id
			getProId(data){
				if(this.navCurrent===0){
					if(this.listData[data.num].checked){
						this.listData[data.num].checked=false
						this.projectId=''
						this.dataid=''
						this.projectName=''
					}else{
						this.listData.forEach(item=>{
							item.checked=false
						})
						this.listData[data.num].checked=true
						this.projectId=data.key
						this.dataid=data.datakey
						this.projectName=data.name
					}	
				}else{
					if(this.listData[data.num].checked){
						this.listData[data.num].checked=false
						this.projectId=''
						this.dataid=''
						this.projectName=''
					}else{
						this.listData.forEach(item=>{
							item.checked=false
						})
						this.listData[data.num].checked=true
						this.projectId=data.key
						this.dataid=data.datakey
						this.projectName=data.name
					}	
				}
				
			},
			addNewPage() {
				let path=''
				if(this.navCurrent===0){
					if (!this.projectId) {
						uni.showToast({
							title: "请选择一条数据",
							icon: "none"
						})
						return;
					}else{
						path = `/pages/readInformation/add?projectId=${this.projectId}&projectName=${this.projectName}`
					}
				}else{
					if (!this.dataid) {
						uni.showToast({
							title: "请选择一条数据",
							icon: "none"
						})
						return;
					}else{
						path = `/pages/readInformation/add?projectId=${this.dataid}&projectName=${this.projectName}`
					}
				}
				this.showChk = false;
				uni.navigateTo({
					url: path
				})
			},
			//获取权限
			async getAuth() {
				const res = await this.$req({
					url: 'bus/reportview/filter.do',
					data: {
						moduleId: 'busProjReportView'
					}
				})
				if (res.data.success) {
					if(res.data.attributes.buttons){
						this.hiddenShow=res.data.attributes.buttons.delReport
					}else{
						this.hiddenShow=false
					}
					if(res.data.attributes.weeks){
						this.dataTimeList=res.data.attributes.weeks
					}else{
						this.dataTimeList=[]
					}
				}
			},
		},
		onLoad(){
			this.getAuth()
			this.heightChange(200)
			this.getDataNumber()
			// this.getDataList(0)
			this.getFlPerson()
			if(uni.getStorageSync('dicData')){
				this.dicData = JSON.parse(uni.getStorageSync('dicData'))
			}
		},
		onShow() {
			this.refreshList();
		},
		onPullDownRefresh(){
			console.log('下拉刷新')
			this.refreshList();
			setTimeout(function() {  
				uni.stopPullDownRefresh();  
			}, 1500);  
		},
		// onReachBottom(){
		// 	const totalPage = Math.ceil(this.total/10);
		// 	const currPage = this.pageNumber;
		// 	if(currPage < totalPage){
		// 		this.pageNumber ++;
		// 		this.getDataList(this.navCurrent)
				
				
		// 	} else {
		// 		this.moreTip = true
		// 	}
		// },
		onShareAppMessage() {
			return {
				imageUrl: 'https://www.szaez.com/sck/share.jpg?v=' + new Date().getTime()
			}
		}
	}
</script>
  
<style lang="scss" scoped>
	page{
		background-color: #e9f0f2;
	}
</style>






